﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
   public class NeedPayService : ServiceHandle, INeedPay
    {
        #region INeedPay Members

     //  ConcreteDaoDataContext dataContext = getDateContext();//new ConcreteDaoDataContext(); 

        public OperationResult<List<tb_NeedPay>> GetAllNeedPay()
        {
            OperationResult<List<tb_NeedPay>> result = new OperationResult<List<tb_NeedPay>>();
            List<tb_NeedPay> list = new List<tb_NeedPay>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllNeedPay();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_NeedPay> GetNeedPayById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_NeedPay> result = new OperationResult<tb_NeedPay>();
            tb_NeedPay receivable;
            try
            {
                receivable = dataContext.GetNeedPayById(id);
                if (receivable == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = receivable;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_NeedPay> CreateNeedPay(tb_NeedPay entity)
        {

            OperationResult<tb_NeedPay> result = new OperationResult<tb_NeedPay>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateNeedPay(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_NeedPay> ModifyNeedPay(tb_NeedPay entity)
        {
            OperationResult<tb_NeedPay> result = new OperationResult<tb_NeedPay>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.ModifyNeedPay(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_NeedPay> DeleteNeedPay(tb_NeedPay entity)
        {
            OperationResult<tb_NeedPay> result = new OperationResult<tb_NeedPay>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.DeleteNeedPay(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
